@extends('Admin.base')
@section('css')

@endsection
@section('style')

@endsection
@section('content')
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-xs2 layui-col-sm2 layui-col-md2">
                    <label class="layui-form-label">发放日期</label>
                    <div class="layui-input-block">
                        <input type="text"  name="start_at" class="layui-input" id="test6" placeholder=" ~ ">
                    </div>
                </div>
                <div class="layui-inline layui-col-xs2 layui-col-sm2 layui-col-md2">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <select name="status" >
                            <option value=''>全部状态</option>
                            @foreach (\App\Models\Marketing::MARKETING_STATUS as $id => $name)
                            <option value="{{$id}}">{{$name}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <div class="layui-btn-group layui-input-block">
                        <button class="layui-btn layui-btn-sm layui-input-block layuiadmin-btn-admin" lay-submit lay-filter="LAY-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="LAY-table" lay-filter="LAY-table"></table>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <a class="layui-btn" href="{{ route('marketing.add') }}">发放优惠券</a>
                </div>
            </script>
        </div>
    </div>
@endsection

@section('script')
    <script src="/js/ajax.js"></script>
    <script>
        layui.use(['form','laydate', 'table', 'laydate'], function(){
            var $ = layui.$
                ,form = layui.form
                ,table = layui.table,
                laydate = layui.laydate;

            table.render({
                elem: '#LAY-table'
                ,toolbar: '#toolbarDemo'
                ,defaultToolbar: []
                ,url: "{{url('/admin/marketing/table')}}"
                ,method: "post"
                ,page: true //开启分页
                ,limit:10
                ,cols: [[
                    {field: 'start_at', title: '发放日期',templet:function(d){

                        return d.start_at?d.start_at.substring(0,10):'' ;
                    }}
                    ,{field:'activity_name', title:'活动名称' }
                    ,{field:'type', title:'规则' ,templet:function(d){
                        if (!d.activity){
                            return '';
                        }
                        if(d.activity.rule_type == 2){
                            return  "满" + d.activity.full + "减" + d.activity.less;
                        }else {
                            return   "立减" + d.activity.less;
                        }
                    }}
                    ,{field: 'amount', title: '发放数量' ,templet:function(d){
                            return d.amount ? d.amount : 0;
                        }}
                    ,{field: 'type', title: '发放类型' ,templet:function(d){
                        return d.type == 1 ? "指定用户" : (d.type == 2 ? "指定会员等级" :"全部用户");
                    }}
                    ,{field: 'scope_title', title: '发放范围',templet:function(d){
                            return   d.scope_title ;
                        }}
                    ,{field: 'number', title: '每人最大获得数量' }
                    ,{field: 'status', title: '发放状态' ,templet:function(d){
                        return d.status == 1 ? "处理中" : "已发送";
                    }}
                ]]

            });

            laydate.render({
                elem: '#test6'
                ,calendar: true
            });
            //监听搜索
            form.on('submit(LAY-search)', function(data){
                var field = data.field;
                //执行重载
                table.reload('LAY-table', {
                    where: field,page: {curr: 1}
                });
            });
        });
    </script>

@endsection